#Install and Load Packages
install.packages("corrplot")
install.packages("data.table")
library(devtools)
install_github("raivokolde/pheatmap")
install.packages("RColorBrewer")
install.packages("ggstatsplot")
install.packages("later")
install.packages("stringdist")
install.packages("sjstats")
install.packages("tidytext")
install.packages("dplyr")
install.packages("stringr")
require(devtools)
install_github("lchiffon/wordcloud2")
install.packages("tidyr")
install.packages("ggrepel")
install.packages("formattable")
install.packages("skimr")
install.packages("DT")
install.packages("devtools") # if you have not installed "devtools" package
devtools::install_github("xvrdm/ggrough")
install.packages("FFTrees")
library(pheatmap)
library(data.table)
library(corrplot)
library(ggplot2)
library(plyr)
library(RColorBrewer)
library(later)
library(stringdist)
library(sjstats)
library(ggstatsplot)
library(tidytext)
library(dplyr)
library(stringr)
library(rtweet)
library(wordcloud2)
library(tidyr)
library(ggrepel)
library(skimr)
library(formattable)
library(DT)
library(ggrough)
library(FFTrees)
library(knitr)
Setting up some basic color variables will keep our charts neat and consistently formatted.
# Create color palettes
bluePalette <- colorRampPalette(brewer.pal(15,"Blues"))(8)
n too large, allowed maximum for palette Blues is 9
Returning the palette you asked for with that many colors
bluePalette <-bluePalette[-c(1,2)] # remove first 2 b/c they are too light to plot
bluePalette
[1] "#BAD6EB" "#88BEDC" "#539ECC" "#2A7AB9" "#0B559F" "#08306B"
bluePalette2 <- c("#C5E2F7", "#92BAD2", "#53789E", "#395877")
##Set the blue color scale since non gender specific
pinkPalette <- c("#FDAB9F", "#FE7F9C", "#DF5286", "#F5C3C2", "#FE5BAC", "#FF69B4", "#FB9AAC")
#set the male, female color scale
genderNeutralCol <- "#C6AE74"
girlCol <- "#E07478"
boyCol <- "#588CA8"
mfPalette <- c(genderNeutralCol, girlCol, boyCol)
#Bring in the data set
df= fread('https://raw.githubusercontent.com/lgellis/STEM/master/DATA-ART-1/Data/FinalData.csv')
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 6213 100 6213 0 0 66181 0 --:--:-- --:--:-- --:--:-- 66806
attach(df)
The following object is masked _by_ .GlobalEnv:
Career
The following objects are masked from df (pos = 3):
Career, Gender, Grade, Horoscope, HrsHomework, ID, IntExt, OptPest, PhysActive,
ScreenTime, Self1, Self2, Sleep, SpendTime1, SpendTime2, Subject, Superpower
The following objects are masked from df (pos = 12):
Career, Gender, Grade, Horoscope, HrsHomework, ID, IntExt, OptPest, PhysActive,
ScreenTime, Self1, Self2, Sleep, SpendTime1, SpendTime2, Subject, Superpower
The following objects are masked from df (pos = 14):
Career, Gender, Grade, Horoscope, HrsHomework, ID, IntExt, OptPest, PhysActive,
ScreenTime, Self1, Self2, Sleep, SpendTime1, SpendTime2, Subject, Superpower
#Bring in the data with normalized job descr
dfNormal <- fread('https://raw.githubusercontent.com/lgellis/STEM/master/DATA-ART-1/Data/FinalDataNormalizedCareer.csv')
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 6087 100 6087 0 0 57725 0 --:--:-- --:--:-- --:--:-- 57971
head(dfNormal)
See how the variables collected relate to one another
####################### CORRELATION ##############################
# Create the Correlation Plots
corDf <- df[ , 8:11]
corDf <-sapply(corDf, FUN = as.numeric)
corDf <-corDf[complete.cases(corDf), ]
#Make the correlation matrix
corMatrix <-cor(corDf, use="complete.obs", method="pearson")
corMatrix
ScreenTime Sleep PhysActive HrsHomework
ScreenTime 1.0000000 -0.48038694 -0.17562140 0.2181979
Sleep -0.4803869 1.00000000 0.01483157 -0.0534581
PhysActive -0.1756214 0.01483157 1.00000000 0.1147035
HrsHomework 0.2181979 -0.05345810 0.11470353 1.0000000
#Plot numerous formats of the correlation matrix
corrplot(corMatrix, type = "upper", order = "hclust", col = c("black", "white"), bg = "lightblue", tl.col = "black")
corrplot(corMatrix, method="circle", tl.col = "black")
corrplot(corMatrix, method="square", tl.col = "black")
corrplot(corMatrix, method="number", tl.col = "black")
corrplot(corMatrix, method="shade", tl.col = "black")
corrplot.mixed(corMatrix, tl.col = "black")
#Gender Based Graphs
# please ignore all of the lazy naming :)
#Screen, Sleep and Gender
scat2 <-ggplot(df, aes(x=Sleep, y=ScreenTime, colour=Gender))
scat2 <- scat2 + scale_color_manual(values= mfPalette) + geom_count()
scat2 + theme_bw() + theme_minimal() +
facet_wrap( ~ Gender, ncol=2) +
labs(title = "Time Spent on Screen vs Sleep Considering Gender",
x = "Hours of Sleep per Night", y = "Hours of Screen Time Per Day")
#Screen, Sleep, Physical Activity and Gender
scat2 <-ggplot(df, aes(x=Sleep, y=ScreenTime, colour=Gender, size=PhysActive))
scat2 <- scat2 + scale_color_manual(values= mfPalette) + geom_point()
scat2 + theme_bw() + theme_minimal() +
facet_wrap( ~ Gender, ncol=2) +
labs(title = "Time Spent on Screen vs Sleep Considering Gender and Physical Activity",
x = "Hours of Sleep per Night", y = "Hours of Screen Time Per Day")
#Homework, Sleep, Physical Activity and Gender
scat2 <-ggplot(df, aes(x=Sleep, y=HrsHomework, colour=Gender, size=PhysActive))
scat2 <- scat2 + scale_color_manual(values= mfPalette) + geom_point()
scat2 + theme_bw() + theme_minimal() +
facet_wrap( ~ Gender, ncol=2) +
labs(title = "Time Spent on Homwork vs Sleep Considering Gender and Physical Activity",
x = "Hours of Sleep per Night", y = "Hours of Homework Time Per Week")
# Numerical Relations
#Sleep and Screentime
scat2 <-ggplot(df, aes(x=Sleep, y=ScreenTime, size=1/5, alpha=0.05))
scat2 <- scat2 + geom_point()
scat2 + stat_smooth(method=lm, fill="#BAD6EB", colour="#08306B", size=2) +
theme_bw() + theme_minimal() +
labs(title = "Time Spent on Sleep vs Screen Time",
x = "Hours of Sleep per Night", y = "Hours of Screen Time Per Day")
#Sleep and Grade
scat2 <-ggplot(df, aes(x=Sleep, y=Grade, size=1/5, alpha=0.05))
scat2 <- scat2 + geom_point()
scat2 + stat_smooth(method=lm, fill="#BAD6EB", colour="#08306B", size=2) +
theme_bw() + theme_minimal() +
labs(title = "Time Spent on Sleep vs Grade",
x = "Hours of Sleep per Night", y = "Grade")
#ScreenTime and Grade
scat2 <-ggplot(df, aes(x=ScreenTime, y=Grade, size=1/5, alpha=0.05))
scat2 <- scat2 + geom_point()
scat2 + stat_smooth(method=lm, fill="#BAD6EB", colour="#08306B", size=2) +
theme_bw() + theme_minimal() +
labs(title = "Screen Time vs Grade",
x = "Hours of Screen Time", y = "Grade")
#Sleep and Screentime - Facet Wrap by Grade to see if it's a common trend without age
# as confounding factor
scat2 <-ggplot(df, aes(x=Sleep, y=ScreenTime, alpha=0.05))
scat2 <- scat2 + geom_point()
scat2 + theme_bw() + theme_minimal() +
stat_smooth(method=lm, fill="#BAD6EB", colour="#08306B", size=1) +
labs(title = "Time Spent on Screen vs Sleep by Grade",
x = "Hours of Sleep per Night", y = "Hours of Screen Time Per Day") +
facet_wrap( ~ Grade, ncol=2)
#Chart 6
violin <-ggplot(df, aes(y=Sleep, x=IntExt))
violin + geom_violin(trim=FALSE, fill="lightblue") +
theme_bw() + theme_minimal() +
labs(title = "Time Spent on Sleep by Social Factors",
x = "Hours of Sleep per Night")
#Sleep, Homework and Subject
scat3 <-ggplot(df, aes(x=HrsHomework, y=Sleep, colour=Subject))
scat3<- scat3 + geom_point() + geom_smooth()
scat3 + facet_wrap( ~ Subject, ncol=2) +
scale_color_manual(values= bluePalette) +
theme_bw() + theme_minimal() +
labs(title = "Time Spent on Homwork vs Sleep Considering Students Favorite Subject",
x = "Hours of Sleep per Night", y = "Hours of Homework Per Week")
# Age differences
# Sleep by Age
sleepTime <-ggplot(df, aes(y=Sleep, x=Grade))
sleepTime + geom_count(trim=FALSE, fill="lightblue") +
theme_bw() + theme_minimal() +
stat_smooth(method=lm, fill="#BAD6EB", colour="#08306B", size=2) +
labs(title = "Time Spent on Sleep by Grade",
y = "Hours of Sleep per Night", x="Grade")
Ignoring unknown parameters: trim
# Homework by Age
homeworkTime <-ggplot(df, aes(y=HrsHomework, x=Grade))
homeworkTime + geom_count(trim=FALSE, fill="lightblue") +
theme_bw() + theme_minimal() +
stat_smooth(method=lm, fill="#BAD6EB", colour="#08306B", size=2) +
labs(title = "Time Spent on Homework by Grade",
y = "Hours of Homework per Week", x="Grade")
Ignoring unknown parameters: trim
# Physical Activity by Age
physTime <-ggplot(df, aes(y=PhysActive, x=Grade))
physTime + geom_count(trim=FALSE, fill="lightblue") +
theme_bw() + theme_minimal() +
stat_smooth(method=lm, fill="#BAD6EB", colour="#08306B", size=2) +
labs(title = "Time Spent on Physical Activity by Grade",
y = "Hours of Physical Activity per Week", x="Grade")
Ignoring unknown parameters: trim
# Screen Time by Age
screenTime <-ggplot(df, aes(y=ScreenTime, x=Grade))
screenTime + geom_count(trim=FALSE, fill="lightblue") +
theme_bw() + theme_minimal() +
stat_smooth(method=lm, fill="#BAD6EB", colour="#08306B", size=2) +
labs(title = "Time Spent on Screens by Grade",
y = "Hours of Screen Time per Day", x="Grade")
Ignoring unknown parameters: trim
#Summary of grade - average screentime, sleep, physical activity etc
gradeSummary <- df %>%
group_by(Grade) %>%
summarize(ScreenTimeDay = mean(ScreenTime, na.rm = TRUE), SleepDay = mean(Sleep, na.rm = TRUE),
PhysActiveDay = mean(PhysActive, na.rm = TRUE), HomeworkDay = mean(HrsHomework, na.rm = TRUE)) %>%
gather(measurement, average, ScreenTimeDay:HomeworkDay)
# ggstatsplot
ggstatsplot::ggscatterstats(
data = df,
x = ScreenTime,
y = Sleep,
title = "Hours Sleep vs Screen Time",
messages = FALSE,
marginal.type = "histogram",
line.color = "#08306B",
xfill = "#BAD6EB",
yfill = "#539ECC",
)
# plot
ggstatsplot::ggbetweenstats(
data = df,
x = Gender,
y = HrsHomework,
messages = FALSE
)
[31mWarning: [39m [34maesthetic `x` was not a factor; converting it to factor[39m
#Histogram
ggstatsplot::gghistostats(
data = df,
x = PhysActive,
title = "Distribution of Physically Active Hours",
type = "parametric", # one sample t-test
test.value = 3, # default value is 0
centrality.para = "mean", # which measure of central tendency is to be plotted
centrality.color = "darkred", # decides color of vertical line representing central tendency
binwidth = 0.10, # binwidth value (experiment until you find the best one)
messages = FALSE # turn off the messages
)
careerGirl %>%
mutate(word = reorder(word, n)) %>%
arrange(desc(n)) %>%
slice(1:10) %>%
ggplot(aes(word, n)) +
geom_col(show.legend = FALSE, fill=girlCol) +
labs(title = "Top 10 Girl Careers",
y=NULL,
x = NULL) +
coord_flip() +
theme_bw() + theme_minimal() +
theme(
text = element_text(size=20, face="bold"),
plot.title = element_text(size=30, face="bold", hjust = 0.5))
)
Error: unexpected ')' in ")"
boyCol <- "#588CA8"
careerBoy %>%
mutate(word = reorder(word, n)) %>%
arrange(desc(n)) %>%
slice(1:10) %>%
ggplot(aes(word, n)) +
geom_col(show.legend = FALSE, fill=boyCol) +
labs(title = "Top 10 Boy Careers",
y=NULL,
x = NULL) +
coord_flip() +
theme_bw() + theme_minimal() +
theme(
text = element_text(size=20, face="bold"),
plot.title = element_text(size=30, face="bold", hjust = 0.5))
#Combine the hobbies column
dfNormal$self <- paste(dfNormal$Self1, dfNormal$Self2, sep= " ")
dfNormal$self
[1] "active competitive" "kind active" "active creative"
[4] "active responsible" "intellegent strong" "funny active"
[7] "joyful lazy" "fun confident" "sad calm"
[10] "smart tired" "funny athletic" "caring responsible"
[13] "kind active" "living annoying" "athletic energetic"
[16] "idk idk" "idk idk" "awesome amazing"
[19] "funny smart" "smart happy" "quite pretty"
[22] "sporty smart" "nice kind" "nice happy"
[25] "fun kind" "wierd awkward" "rebel small"
[28] "funny loud" "anoying fun" "talk awsome"
[31] "childish annoying" "moody intense" "loud unpredictable"
[34] "shy curious" "creative curious" "quiet expressive"
[37] "curious friendly" "shy persistent" "tall asian"
[40] "funny energitic" "simple n/a" "Sporty Strong"
[43] "talkative beyond not annoying" "n/a n/a" "creative caring"
[46] "talkative caring" "empathetic kind" "optimistic extravert"
[49] "nice outgoing" "athletic fidgety" "Fun Sweet"
[52] "pretty sporty" "happy kind" "greatful awesome"
[55] "cool awesome" "cool active" "generouse kind"
[58] "nice nice" "funny kind" "nice funny"
[61] "Childish Lazy" "Sarcastic Sassy" "Energetic Curious"
[64] "Quiet Boring" "Weird Active" "Funny Shy"
[67] "Chill Tall" "Active Cool" "Intelligent Athletic"
[70] "Annoying Awesome" "Athletic Amazing" "Shy Embarassed"
[73] "Active Athletic" "thoughtful friendly" "weird odd"
[76] "funny awesome" "active fun" "funny small"
[79] "negative sneaky" "friendly creative" "funny nice"
[82] "angry awesome" "art cats" "Active Smart"
[85] "Kind Happy" "Happy Active" "Competetive Kind"
[88] "Gamer Sporty" "Smart Sweet" "Active Smart"
[91] "Gamer Smart" "Active Smart" "Gamer Annoying"
[94] "sassy funny" " " "loyal artistic"
[97] "athletic social" "funny rude" "funny athletic"
[100] "jerk dishonest" "funny athletic" "agressive calm"
[103] "small funny" "Human Person" "Annoying stuburn"
[106] "funny confused" "funny outgoing" "Hilarious awesome"
[109] "Fashionable awesome" "smart active" "smart active"
[112] "athletic smart" "athletic smart" "sassy happy"
[115] "fun happy" "athletic thiccc" "funny annoying"
[118] "smart blonde" "the goat" "smart nice"
[121] "calm happy" "overly energetic impatient" "funny athletic"
[124] "Bookworm Annoying" "Wierd Crazy" "Chill Dude"
[127] "Witty Condesending" "Smart Sporty" "Lazy Gifted"
[130] "Smart Video Game Lover" "Smart Extreverted" "Friendly Shy"
[133] "Fun Extreverted" "athletic intelligent" "weird cool"
[136] "cheerful optimistic" "petty basic" "adventurous n/a"
[139] "peculiar sassy" "cool cat" "small blond"
[142] "funny athletic" "laid back setericle" "shy active"
[145] "active sporty" "different hungry" " weird"
[148] "hungry friendly" "smart smart" "positive lazy"
[151] "lazy pretty" "unsure smart" "shy fun"
[154] "empathetic observant" "clueless funny" "determined caring"
[157] "talkative witty" "happy annoying" "funny loyal"
[160] "fun caring" "extraverted sassy" "free spirited creative"
[163] "happy good" "weird korean" "happy shy"
[166] "lazy energetic" "active tall" "short active"
[169] "shy quiet" "emotional kind" "active tall"
[172] "active happy" "calm funny" "friendly funny"
[175] "indecisive active" "fun cool" "lazy funky"
[178] "sporty smart" "load energitic" "fun energetic"
[181] "agressive anoying" "nice smart" "fun energetic"
[184] "hyper flimsy" "tired smart"
#Unnest the words - code via Tidy Text
table2 <- dfNormal %>%
unnest_tokens(word, self)
#remove stop words - aka typically very common words such as "the", "of" etc
self <- table2 %>%
anti_join(stop_words)
Joining, by = "word"
self
selfGirl <- table2 %>%
anti_join(stop_words) %>%
filter(Gender == "female")
Joining, by = "word"
selfBoy <- table2 %>%
anti_join(stop_words) %>%
filter(Gender == "male")
Joining, by = "word"
#do a word count
self <- self %>%
dplyr::count(word, sort = TRUE)
self
selfGirl <- selfGirl %>%
dplyr::count(word, sort = TRUE)
selfGirl
selfBoy <- selfBoy %>%
dplyr::count(word, sort = TRUE)
selfBoy
#download symbol
url <- "https://github.com/lgellis/STEM/blob/master/DATA-ART-1/Symbols/heart.png?raw=true"
heartimg <- "heart.png"
download.file(url, heartimg) # download file
trying URL 'https://github.com/lgellis/STEM/blob/master/DATA-ART-1/Symbols/heart.png?raw=true'
Content type 'image/png' length 28086 bytes (27 KB)
==================================================
downloaded 27 KB
#Make wordcloud
wordcloud2(self, size=1)
wordcloud2(self, size=3, figPath = heartimg )
wordcloud2(selfBoy, size=1.5, figPath = heartimg, color=boyCol )
wordcloud2(selfGirl, size=1.5, figPath = heartimg, color=girlCol )
# Self bar charts
selfGirl$gender <- 'female'
selfBoy$gender <- 'male'
fullSelf <-rbind(selfBoy, selfGirl)
fullSelf
fullSelf %>%
mutate(word = reorder(word, n)) %>%
ggplot(aes(word, n, fill = gender)) +
geom_col(show.legend = FALSE) +
facet_wrap(~gender, scales = "free_y") +
scale_fill_manual(values=c(girlCol, boyCol)) +
labs(y = "Male vs Female Self Description",
x = NULL) +
coord_flip() +
theme_bw() + theme_minimal()
# Sentiment Analysis - do on the full data
?get_sentiments
#afinn is numeric scale, bing is +ve/-ve,
#nrc is more detailed (ie trust, fear etc), loughran is +ve/-ve
sentiments <- get_sentiments("afinn")
sentiments
## Get raw word and gender (1 row per instance of assignment)
head(dfNormal)
self1 <- as.data.frame(dfNormal[,c("Gender", "Self1")])
self2 <- as.data.frame(dfNormal[,c("Gender", "Self2")])
head(self2)
#TO DO rename self1 and self2
names(self1)[2]<-"word"
names(self2)[2]<-"word"
fullStackSelf <-rbind(self1, self2)
head(fullStackSelf)
#add sentiment
sentiments <- get_sentiments("afinn")
fullStackSelfSentiment <- fullStackSelf %>%
inner_join(sentiments)
Joining, by = "word"
fullStackSelfSentiment
#Averages
summaryGenderSentiment <- fullStackSelfSentiment %>%
group_by(Gender) %>%
dplyr::summarize(avgSentimentScore = mean(score, na.rm = TRUE),
medSentimentScore = median(score, na.rm = TRUE),
countWords = length(word))
names(summaryGenderSentiment) <- c("Gender", "Avg Sentiment Score", "Median Sentiment Score", "Word Count")
formattable(summaryGenderSentiment,
list("Avg Sentiment Score" = color_tile("transparent", "#00A86B")))
as.datatable(formattable(summaryGenderSentiment))
#box plot
ggplot(fullStackSelfSentiment, aes(x=Gender, y=score, fill=Gender)) +
geom_boxplot(notch=TRUE) +
scale_fill_manual(values=c(genderNeutralCol, girlCol, boyCol)) +
labs(title = "Sentiment Score for Male vs Female Self Description",
x = NULL) +
coord_flip() +
theme_bw() + theme_minimal() +
theme(
text = element_text(size=14 ),
plot.title = element_text(size=18, face="bold", hjust = 0.5))
Note that the output will not be displayed in
##normal
screenTime <-ggplot(df, aes(y=ScreenTime, x=PhysActive))
screenTime + geom_count(trim=FALSE, fill="lightblue") +
theme_bw() + theme_minimal() +
labs(title = "Time Spent on Screens by Grade",
y = "Hours of Screen Time per Day", x="Hours Physically Active a Week")
Ignoring unknown parameters: trim
#The docs can be found here: https://github.com/thomasp85/gganimate/blob/master/README.md
library(gganimate)
library(tweenr)
library(gganimate)
##With Animation
screenTime <-ggplot(df, aes(y=ScreenTime, x=HrsHomework))
screenTime + geom_count(trim=FALSE, fill="lightblue") +
theme_bw() + theme_minimal() +
# Here comes the gganimate specific bits
labs(title = 'Grade: {frame_time}', x = 'Hours Homework a Week', y = 'Hours of Screen Time per Day') +
transition_time(Grade) +
ease_aes('linear')
Ignoring unknown parameters: trim
Frame 0 (1%)
Frame 1 (2%)
Frame 2 (3%)
Frame 3 (4%)
Frame 4 (5%)
Frame 5 (6%)
Frame 6 (7%)
Frame 7 (8%)
Frame 8 (9%)
Frame 9 (10%)
Frame 10 (11%)
Frame 11 (12%)
Frame 12 (13%)
Frame 13 (14%)
Frame 14 (15%)
Frame 15 (16%)
Frame 16 (17%)
Frame 17 (18%)
Frame 18 (19%)
Frame 19 (20%)
Frame 20 (21%)
Frame 21 (22%)
Frame 22 (23%)
Frame 23 (24%)
Frame 24 (25%)
Frame 25 (26%)
Frame 26 (27%)
Frame 27 (28%)
Frame 28 (29%)
Frame 29 (30%)
Frame 30 (31%)
Frame 31 (32%)
Frame 32 (33%)
Frame 33 (34%)
Frame 34 (35%)
Frame 35 (36%)
Frame 36 (37%)
Frame 37 (38%)
Frame 38 (39%)
Frame 39 (40%)
Frame 40 (41%)
Frame 41 (42%)
Frame 42 (43%)
Frame 43 (44%)
Frame 44 (45%)
Frame 45 (46%)
Frame 46 (47%)
Frame 47 (48%)
Frame 48 (49%)
Frame 49 (50%)
Frame 50 (51%)
Frame 51 (52%)
Frame 52 (53%)
Frame 53 (54%)
Frame 54 (55%)
Frame 55 (56%)
Frame 56 (57%)
Frame 57 (58%)
Frame 58 (59%)
Frame 59 (60%)
Frame 60 (61%)
Frame 61 (62%)
Frame 62 (63%)
Frame 63 (64%)
Frame 64 (65%)
Frame 65 (66%)
Frame 66 (67%)
Frame 67 (68%)
Frame 68 (69%)
Frame 69 (70%)
Frame 70 (71%)
Frame 71 (72%)
Frame 72 (73%)
Frame 73 (74%)
Frame 74 (75%)
Frame 75 (76%)
Frame 76 (77%)
Frame 77 (78%)
Frame 78 (79%)
Frame 79 (80%)
Frame 80 (81%)
Frame 81 (82%)
Frame 82 (83%)
Frame 83 (84%)
Frame 84 (85%)
Frame 85 (86%)
Frame 86 (87%)
Frame 87 (88%)
Frame 88 (89%)
Frame 89 (90%)
Frame 90 (91%)
Frame 91 (92%)
Frame 92 (93%)
Frame 93 (94%)
Frame 94 (95%)
Frame 95 (96%)
Frame 96 (97%)
Frame 97 (98%)
Frame 98 (99%)
Frame 99 (100%)
Finalizing encoding... done!
## Second Animation
ggplot(df, aes(y=ScreenTime, x=HrsHomework, color = Gender)) +
geom_point() +
theme_bw() + theme_minimal() +
# Here comes the gganimate specific bits
labs(title = 'Grade: {frame_time}', x = 'Hours Homework a Week', y = 'Hours of Screen Time per Day') +
transition_time(Grade) +
ease_aes('linear') +
scale_color_manual(values=mfPalette)
Frame 0 (1%)
Frame 1 (2%)
Frame 2 (3%)
Frame 3 (4%)
Frame 4 (5%)
Frame 5 (6%)
Frame 6 (7%)
Frame 7 (8%)
Frame 8 (9%)
Frame 9 (10%)
Frame 10 (11%)
Frame 11 (12%)
Frame 12 (13%)
Frame 13 (14%)
Frame 14 (15%)
Frame 15 (16%)
Frame 16 (17%)
Frame 17 (18%)
Frame 18 (19%)
Frame 19 (20%)
Frame 20 (21%)
Frame 21 (22%)
Frame 22 (23%)
Frame 23 (24%)
Frame 24 (25%)
Frame 25 (26%)
Frame 26 (27%)
Frame 27 (28%)
Frame 28 (29%)
Frame 29 (30%)
Frame 30 (31%)
Frame 31 (32%)
Frame 32 (33%)
Frame 33 (34%)
Frame 34 (35%)
Frame 35 (36%)
Frame 36 (37%)
Frame 37 (38%)
Frame 38 (39%)
Frame 39 (40%)
Frame 40 (41%)
Frame 41 (42%)
Frame 42 (43%)
Frame 43 (44%)
Frame 44 (45%)
Frame 45 (46%)
Frame 46 (47%)
Frame 47 (48%)
Frame 48 (49%)
Frame 49 (50%)
Frame 50 (51%)
Frame 51 (52%)
Frame 52 (53%)
Frame 53 (54%)
Frame 54 (55%)
Frame 55 (56%)
Frame 56 (57%)
Frame 57 (58%)
Frame 58 (59%)
Frame 59 (60%)
Frame 60 (61%)
Frame 61 (62%)
Frame 62 (63%)
Frame 63 (64%)
Frame 64 (65%)
Frame 65 (66%)
Frame 66 (67%)
Frame 67 (68%)
Frame 68 (69%)
Frame 69 (70%)
Frame 70 (71%)
Frame 71 (72%)
Frame 72 (73%)
Frame 73 (74%)
Frame 74 (75%)
Frame 75 (76%)
Frame 76 (77%)
Frame 77 (78%)
Frame 78 (79%)
Frame 79 (80%)
Frame 80 (81%)
Frame 81 (82%)
Frame 82 (83%)
Frame 83 (84%)
Frame 84 (85%)
Frame 85 (86%)
Frame 86 (87%)
Frame 87 (88%)
Frame 88 (89%)
Frame 89 (90%)
Frame 90 (91%)
Frame 91 (92%)
Frame 92 (93%)
Frame 93 (94%)
Frame 94 (95%)
Frame 95 (96%)
Frame 96 (97%)
Frame 97 (98%)
Frame 98 (99%)
Frame 99 (100%)
Finalizing encoding... done!
ggplot(df, aes(y=ScreenTime, x=HrsHomework, color = Gender)) +
geom_point() +
theme_bw() + theme_minimal() +
# Here comes the gganimate specific bits
labs(title = 'Grade: {frame_time}', x = 'Hours Homework a Week', y = 'Hours of Screen Time per Day') +
transition_time(Grade) +
ease_aes('sine-in-out') +
scale_color_manual(values=mfPalette)
## With better titles
ggplot(df, aes(y=ScreenTime, x=HrsHomework, color = Gender)) +
geom_point(size =7, alpha = 0.4) +
theme_bw() + theme_minimal() +
# Here comes the gganimate specific bits
transition_states(
Grade,
transition_length = 4,
state_length = 1
) +
enter_fade() +
exit_shrink() +
ease_aes('sine-in-out') +
scale_color_manual(values=mfPalette) +
labs(title = 'Grade: {closest_state}')
Frame 0 (1%)
Frame 1 (2%)
Frame 2 (3%)
Frame 3 (4%)
Frame 4 (5%)
Frame 5 (6%)
Frame 6 (7%)
Frame 7 (8%)
Frame 8 (9%)
Frame 9 (10%)
Frame 10 (11%)
Frame 11 (12%)
Frame 12 (13%)
Frame 13 (14%)
Frame 14 (15%)
Frame 15 (16%)
Frame 16 (17%)
Frame 17 (18%)
Frame 18 (19%)
Frame 19 (20%)
Frame 20 (21%)
Frame 21 (22%)
Frame 22 (23%)
Frame 23 (24%)
Frame 24 (25%)
Frame 25 (26%)
Frame 26 (27%)
Frame 27 (28%)
Frame 28 (29%)
Frame 29 (30%)
Frame 30 (31%)
Frame 31 (32%)
Frame 32 (33%)
Frame 33 (34%)
Frame 34 (35%)
Frame 35 (36%)
Frame 36 (37%)
Frame 37 (38%)
Frame 38 (39%)
Frame 39 (40%)
Frame 40 (41%)
Frame 41 (42%)
Frame 42 (43%)
Frame 43 (44%)
Frame 44 (45%)
Frame 45 (46%)
Frame 46 (47%)
Frame 47 (48%)
Frame 48 (49%)
Frame 49 (50%)
Frame 50 (51%)
Frame 51 (52%)
Frame 52 (53%)
Frame 53 (54%)
Frame 54 (55%)
Frame 55 (56%)
Frame 56 (57%)
Frame 57 (58%)
Frame 58 (59%)
Frame 59 (60%)
Frame 60 (61%)
Frame 61 (62%)
Frame 62 (63%)
Frame 63 (64%)
Frame 64 (65%)
Frame 65 (66%)
Frame 66 (67%)
Frame 67 (68%)
Frame 68 (69%)
Frame 69 (70%)
Frame 70 (71%)
Frame 71 (72%)
Frame 72 (73%)
Frame 73 (74%)
Frame 74 (75%)
Frame 75 (76%)
Frame 76 (77%)
Frame 77 (78%)
Frame 78 (79%)
Frame 79 (80%)
Frame 80 (81%)
Frame 81 (82%)
Frame 82 (83%)
Frame 83 (84%)
Frame 84 (85%)
Frame 85 (86%)
Frame 86 (87%)
Frame 87 (88%)
Frame 88 (89%)
Frame 89 (90%)
Frame 90 (91%)
Frame 91 (92%)
Frame 92 (93%)
Frame 93 (94%)
Frame 94 (95%)
Frame 95 (96%)
Frame 96 (97%)
Frame 97 (98%)
Frame 98 (99%)
Frame 99 (100%)
Finalizing encoding... done!
ggplot(df, aes(x="", y=ScreenTime)) +
geom_boxplot(fill = genderNeutralCol, alpha = 0.8, binwidth=3) +
theme_bw() + theme_minimal() + facet_wrap(~Grade)
Ignoring unknown parameters: binwidth
ggplot(df, aes(x="", y=ScreenTime)) +
geom_boxplot(fill = boyCol, alpha = 0.8, binwidth=3) +
theme_bw() + theme_minimal() +
# Here comes the gganimate specific bits
transition_states(
Grade,
transition_length = 4,
state_length = 1
) +
enter_fade() +
exit_shrink() +
ease_aes('sine-in-out') +
scale_color_manual(values=mfPalette) +
labs(title = 'Grade: {closest_state}',
x ="", y = "Screen Time") +
theme(
plot.title = element_text(size=30, face="bold.italic", hjust = 0.5),
axis.title.y = element_text(size=14, face="bold")
)
Ignoring unknown parameters: binwidth